<?php

/**
 * Created by PhpStorm.
 * User: Apache
 * Date: 2019/10/27
 * Time: 10:52
 */

namespace app\api\model;

use think\Db;
use think\Model;

class Companyset extends Model
{

    // 表名
    public $name = 'companyset';
    /**
     * 插入数据
     * @param $data
     * @return bool|int|string
     */
    public function insertData($data)
    {
        $r = $this->insertGetId($data);
        if (!$r) {
            return false;
        }

        return $r;
    }

    /**
     * 编辑数据
     * @param $data
     * @param $where
     * @return Project
     */
    public function updateBywhere($data, $where)
    {
        $r = $this->where($where)->update($data);
        return $r;
    }

    /**
     * 获取总数
     * @param array $where
     * @return int|string
     * @throws \think\Exception
     */
    public function countWhere($where = [])
    {
        $r = $this->where($where)->count();
        return $r;
    }

    /**
     * 假删
     * @param array $where
     * @return Project
     */
    public function deleteWhere($where = [])
    {
        $r = $this->where($where)->update(['is_delete' => 1]);
        return $r;
    }

    /**
     * 获取详情
     * @param array $where
     * @return array|false|\PDOStatement|string|Model
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function findWhere($where = [])
    {

        $r = $this->where($where)->find();
        return $r;
    }

    /**
     * 分页列表
     * @param array $where
     * @param string $order
     * @param int $current
     * @param int $pagesize
     * @return false|\PDOStatement|string|\think\Collection
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function listWherePage($where = [], $order = 'id desc', $current = 0, $pagesize = 10)
    {
        $r = $this->where($where)->order($order)->limit($current . ',' . $pagesize)->select();
        return $r;
    }

    //企业设置  执行新增
    public function insertDataf1($data)
    {
        $this->name = 'companyf1';
        // $r = $this->insertGetId($data);
        $r = Db::name('companyf1')->insertGetId($data);
        var_dump($r);
        die;
        if (!$r) {
            return false;
        }
        return $r;
    }

    //下拉执行新增，多表 根据类别来 下拉方法 集合 
    public function inset_common_xla($data, $tbname)
    {

        //  $data1['account']="222";
        // $r = Db::name('admin')->insertGetId($data1);
        $r = Db::name($tbname)->insertGetId($data);
        if (!$r) {
            return false;
        }
        return $r;
    }
    
    //下拉执行编辑，多表 根据类别来 下拉方法 集合 
    public function edit_common_xla($data, $where, $tbname)
    {
        $r = Db::name($tbname)
            ->where($where)
            ->update($data);
        if (!$r) {
            return false;
        }
        return $r;
    }
    //下拉执行查询所有的列表，多表 根据类别来 下拉方法 集合 
    public function selAll_common_xla($data = "", $where = "", $tbname)
    {
        $r = Db::name($tbname)
            ->where($where)
            ->select();
        if (!$r) {
            return false;
        }
        return $r;
    }
    //下拉执行查询 明细，多表 根据类别来 下拉方法 集合 
    public function selDetail_common_xla($data = "", $where = "", $tbname)
    {
        $r = Db::name($tbname)
            ->where($where)
            ->select();
        if (!$r) {
            return false;
        }
        return $r;
    }

    // 下拉 func  ed 




}
